package com.filter;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author zhangwei
 * @version 1.0
 * @date 2023/9/30 12:07
 */
@Component
public class CustomRouteLocator {




    @Bean
    public RouteLocator CustomRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("SERVICE-ACL", r -> r.path("/mytest/**")
                        .filters(f->f.rewritePath("/mytest/","/five/"))
                .uri("http://localhost:9090")
                )
                .route("baidu",r->r.path("/mybaidu/**")
                        .filters(f->f.rewritePath("/mybaidu","/"))
                        .uri("http://www.baidu.com")
                )
                .build();


                /* .route("path_route", r -> r.path("/get")
                         .uri("http://httpbin.org"))
                 .route("host_route", r -> r.host("*.myhost.org")
                         .uri("http://httpbin.org"))
                 .route("rewrite_route", r -> r.host("*.rewrite.org")
                         .filters(f -> f.rewritePath("/foo/(?<segment>.*)", "/${segment}"))
                         .uri("http://httpbin.org"))
                 .route("hystrix_route", r -> r.host("*.hystrix.org")
                         .filters(f -> f.hystrix(c -> c.setName("slowcmd")))
                         .uri("http://httpbin.org"))
                 .route("hystrix_fallback_route", r -> r.host("*.hystrixfallback.org")
                         .filters(f -> f.hystrix(c -> c.setName("slowcmd").setFallbackUri("forward:/hystrixfallback")))
                         .uri("http://httpbin.org"))*/
                /*.route("limit_route", r -> r
                        .host("*.limited.org").and().path("/anything/**")
                        .filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter())))
                        .uri("http://httpbin.org"))*/

    }
}
